package com.recsmile.sgs.client.operations;

import com.kael.sgs.core.Command;
import com.recsmile.sgs.client.card.Card;
import com.recsmile.sgs.client.entity.Activatable;
import com.recsmile.sgs.client.entity.Hero;
import com.recsmile.sgs.client.ui.components.CardGui;
import com.recsmile.sgs.client.ui.components.CardUI;
import com.recsmile.sgs.client.ui.components.EquipmentUI;
import com.recsmile.sgs.client.ui.components.GamePanel;
import com.recsmile.sgs.client.ui.components.HeroUI;
import com.recsmile.sgs.client.ui.components.PlayerUI;

public abstract class SimpleCardOperation implements Operation {

	private CardGui card;
	private GamePanel<? extends Hero> panel;

	@Override
	public final void onCanceled() {
		card.setActivated(false);
		panel.getContent().setConfirmEnabled(false);
		panel.getContent().setCancelEnabled(false);
		panel.popOperation();
	}

	@Override
	public final void onConfirmed() {
		onCanceled();
		panel.getCurrentOperation().onConfirmed();
		panel.getChannel().send(getCommand(card == null ? null : card.getCard()));
	}
	
	protected abstract Command<?> getCommand(Card card);

	@Override
	public final void onCardClicked(CardUI card) {
		onCanceled();
		if (card != this.card) {
			panel.getCurrentOperation().onCardClicked(card);
		}
	}

	@Override
	public final void onEnded() {
		onCanceled();
		panel.getCurrentOperation().onEnded();
	}

	@Override
	public final void onActivated(GamePanel<? extends Hero> panel, Activatable source) {
		this.panel = panel;
		this.card = (CardGui) source;
		panel.getContent().setConfirmEnabled(true);
		panel.getContent().setCancelEnabled(true);
	}

	@Override
	public void onPlayerClicked(PlayerUI player) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onSelfClicked(HeroUI<? extends Hero> self) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onEquipmentClicked(EquipmentUI equipment) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Command getNext() {
		// TODO Auto-generated method stub
		return null;
	}

}